package com.chinasoft.mall.activity.subActivity.search;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.widget.Toast;

import com.chinasoft.mall.R;
import com.chinasoft.mall.activity.BaseActivity;
import com.chinasoft.mall.activity.MainActivity;
import com.chinasoft.mall.activity.adapter.SearchListAdapter;
import com.chinasoft.mall.model.BaseBean;
import com.chinasoft.mall.model.response.SearchGoodsBean;
import com.chinasoft.mall.widget.LoadListView;
import com.chinasoft.mall.widget.LoadListView.OnRefreshListener;

public class SearchListActivity extends BaseActivity implements OnRefreshListener {
	
	private LoadListView searchlist;
	private BaseBean search_bb;
	private SearchListAdapter slAdapter;
	private List<SearchGoodsBean> sgbs=new ArrayList<SearchGoodsBean>();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sy_more_modellist2);
		initView();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		initRequest();
	}

	private void initRequest() {
		if (sz != null) {
			search_bb = (BaseBean) sz;
			search_bb.reqData.put("pageNo", "1");
			search_bb.reqData.put("pageSize", "10");
			control.sendMessage(search_bb);
		} else {
			Toast.makeText(this, "数据获取失败", Toast.LENGTH_LONG).show();
			((MainActivity)this.getParent()).backCurrentActivity(false);
		}
	}

	private void initView() {
		searchlist=(LoadListView) findViewById(R.id.modellist);
		slAdapter=new SearchListAdapter((MainActivity)this.getParent(), null);
		searchlist.setAdapter(slAdapter);
		searchlist.setonRefreshListener(this);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void success(BaseBean obj) {
		super.success(obj);
		if(obj.equals(search_bb)){
			if(obj.getResData()!=null&&obj.getResData().getData()!=null){
				sgbs.addAll((List<SearchGoodsBean>)obj.getResData().getData());
				slAdapter.setData(sgbs);
				searchlist.onRefreshComplete();
			}
		}
	}

	@Override
	public void onRefresh() {
		search_bb.reqData.put("pageNo", (Integer.parseInt(search_bb.reqData.get("pageNo"))+1)+"");
		control.postMessage(search_bb);
	}
}
